home *** CD-ROM | disk | FTP | other *** search
-
- /* ReadBlock.c Routines for reading and writing blocks */
-
- #include <exec/io.h>
- #include <devices/trackdisk.h>
-
- struct IOStdReq *OpenTDIO(unit)
- UBYTE unit;
- {
- struct IOStdReq *diskio;
- struct MsgPort *readreply;
- int error = -1;
-
- if (readreply = (void *) CreatePort(0, 0))
- {
- if (diskio = (void *) CreateStdIO(readreply))
- {
- error = OpenDevice(TD_NAME, unit, diskio, 0);
- }
- }
- if (error == 0) return(diskio);
- else return(NULL);
- }
-
- int ReadSBlock(io, first_block, blocks, buffer)
- struct IOStdReq *io;
- WORD first_block, blocks;
- UBYTE *buffer;
- {
- io->io_Command = CMD_READ;
- io->io_Data = buffer;
- io->io_Length = blocks*512L;
- io->io_Offset = first_block*512L;
- DoIO(io);
- return((int) io->io_Error);
- }
-
- int WriteSBlock(io, first_block, blocks, buffer)
- struct IOStdReq *io;
- WORD first_block, blocks;
- UBYTE *buffer;
- {
- int error;
-
- io->io_Command = CMD_WRITE;
- io->io_Data = buffer;
- io->io_Length = blocks*512L;
- io->io_Offset = first_block*512L;
- DoIO(io);
- error = io->io_Error;
-
- io->io_Command = CMD_UPDATE;
- DoIO(io);
- if (!error) error = io->io_Error;
- return(error);
- }
-
- void MotorOff(io)
- struct IOStdReq *io;
- {
- io->io_Command = TD_MOTOR;
- io->io_Length = 0L;
- DoIO(io);
- }
-
- void CloseTDIO(io)
- struct IOStdReq *io;
- {
- struct MsgPort *ReplyPort;
-
- if (io)
- {
- ReplyPort = io->io_Message.mn_ReplyPort;
- CloseDevice(io);
- DeleteStdIO(io);
- if (ReplyPort) DeletePort(ReplyPort);
- }
- }
-
- int ReadBlocks(unit, first_block, blocks, buffer)
- UBYTE unit;
- WORD first_block, blocks;
- UBYTE *buffer;
- {
- struct IOStdReq *io;
- int error;
-
- io = OpenTDIO(unit);
- error = ReadSBlock(io, first_block, blocks, buffer);
- MotorOff(io);
- CloseTDIO(io);
- return(error);
- }
-
- int WriteBlocks(unit, first_block, blocks, buffer)
- UBYTE unit;
- WORD first_block, blocks;
- UBYTE *buffer;
- {
- struct IOStdReq *io;
- int error;
-
- io = OpenTDIO(unit);
- error = WriteSBlock(io, first_block, blocks, buffer);
- MotorOff(io);
- CloseTDIO(io);
- return(error);
- }
-